﻿if (typeof(Seq) == 'undefined') Seq = new Object();

if (typeof (Seq.UI) == 'undefined') Seq.UI = new Object();

Seq.UI._closePopupMenu = function(evt, id) {
	var el = $(id);
	new Effect.Fade(el, { duration: 0.3 });
}

Seq.UI._clickPopupMenu = function(evt, id, cb) {
	Seq.UI._closePopupMenu(evt, id);
	cb();
}

Seq.UI.OpenPopupMenu = function(x, y, id, items) {
	var ulel = document.createElement('ul');
	for (var j = 0; j < items.length; j++) {
		var liel = document.createElement('li');
		ulel.appendChild(liel);
		// liel.className = items[j].className || '';

		var ael = document.createElement('a');
		liel.appendChild(ael);
		Event.observe(ael, 'click', Seq.UI._clickPopupMenu.bindAsEventListener(this, id, items[j].callback));

		ael.appendChild(document.createTextNode(items[j].name));
	}

	var el = $(id);
	el.className = 'popupmenu';
	el.style.position = 'absolute';
	el.style.left = (x - 40) + 'px';
	el.style.top = (y - 15) + 'px';
	el.innerHTML = '';
	el.appendChild(ulel);
	// Event.observe( el, 'mouseout', Seq.UI._closePopupMenu.bindAsEventListener( this, id ) );
	Element.show(el);
	new Effect.Appear(el, { duration: 0.2 });
}

Seq.UI.SetDropdownValue = function(el, value) {
	var el2 = $(el);
	var sel = 0;
	for (var j = 0; j < el2.options.length; j++) {
		if (el2.options[j].value == value)
			sel = j;
	}
	el.selectedIndex = sel;
}

Seq.UI.GetDropdownValue = function(el, defaultvalue) {
	var el2 = $(el);
	var val = '';
	if( typeof(defaultvalue) != 'undefined' )
		val = defaultvalue;
	if (el2.selectedIndex >= 0)
		val = el2.options[el2.selectedIndex].value;
	return val;
}

Seq.UI.FindListItem = function(list, propname, propvalue) {
	for (var j = 0; j < list.length; j++)
		if (list[propname] == propvalue)
		return list[propname];
	return null;
}

Seq.UI.GetListItemID = function(list, itemid) {
	return Seq.UI.FindListItem(list, 'id', itemid);
}


